﻿@model Tuple<List<deviceManage.Models.BuyContract>, deviceManage.Models.Project,List<Depart>>
@{
    ViewData["Title"] = "项目管理";
}
<style>

    .layui-layout-body {
        overflow: auto;
    }
</style>
 
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <form class="layui-form" action="doCreate" lay-filter="saveForm">
                        <input type="hidden" name="id" id="id" value="@Model.Item2.Id" />

                        <div class="layui-card">
                            <div class="layui-card-header">项目基本信息</div>
                            <div class="layui-card-body" style="padding: 15px;">
                                 
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">项目名称</label>
                                        <div class="layui-input-inline">
                                            <input type="text" vertype="tips"  name="Name" value="@Model.Item2.Name" lay-verify="required" autocomplete="off" class="layui-input" maxlength="100">
                                        </div>
                                    </div>

                                    <div class="layui-inline">
                                        <label class="layui-form-label">建设单位</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="DevelopUnit" value="@Model.Item2.DevelopUnit" lay-verify="required" autocomplete="off" class="layui-input" maxlength="80">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label" style="width:100px;">使用单位</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="UseUnit" value="@Model.Item2.UseUnit" lay-verify="required" autocomplete="off" class="layui-input" maxlength="80">
                                        </div>
                                    </div>

                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">绑定合同</label>
                                        <div class="layui-input-inline">
                                            <select name="ContractId">
                                                @foreach (var x in Model.Item1)
                                                {
                                                    @if (x.Id.Equals(Model.Item2.ContractId))
                                                    {
                                                        <option selected value="@x.Id">@x.Title</option>
                                                    }
                                                    else
                                                    {
                                                        <option value="@x.Id">@x.Title</option>
                                                    }
                                                }
                                            </select>
                                        </div>
                                    </div>

                                    <div class="layui-inline">
                                        <label class="layui-form-label">开始时间</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly="readonly" value="@if(Model.Item2.StartTime != null){@Model.Item2.StartTime.ToString().Substring(0, 10);} " name="StartTime" id="StartDate" lay-verify="required" autocomplete="off" class="layui-input date">

                                        </div>

                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label" style="width:100px;">投资金额(元）</label>
                                        <div class="layui-input-inline">
                                            <input style="text-align:right;padding-right:5px;" type="text" name="amount" value="@Model.Item2.Amount" lay-verify="money" autocomplete="off" class="layui-input" maxlength="20">
                                        </div>
                                    </div>

                                </div>


                                <div class="layui-form-item">

                                    <div class="layui-inline">
                                        <label class="layui-form-label">所属部门</label>
                                        <div class="layui-input-inline">
                                            <select name="DepartId">
                                                <option></option>
                                                @foreach (Depart item in Model.Item3)
                                                {
                                                    @if (item.Id.Equals(Model.Item2.DepartId))
                                                    {
                                                        <option value="@item.Id" selected>@item.Name</option>
                                                    }
                                                    else
                                                    {
                                                        <option value="@item.Id">@item.Name</option>
                                                    }

                                                }
                                            </select>
                                        </div>
                                    </div>


                                    <div class="layui-inline" style="width: 540px;">
                                        <label class="layui-form-label">参与人</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="Participate" value="@Model.Item2.Participate"   autocomplete="off" class="layui-input" maxlength="100">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="layui-tab layui-tab-card" style="background-color:white;">
                            <ul class="layui-tab-title">
                                <li class="layui-this">立项文件</li>
                                <li>招标文件</li>
                                <li>项目建设文件</li>
                                <li>项目验收文件</li>
                                <li>项目培训文件</li>
                                <li>对应设备文件</li>
                                <li>其他文件</li>
                            </ul>
                            <div class="layui-tab-content">
                                <div class="layui-tab-item layui-show">
                                    <button type="button" class="layui-btn layui-btn-xs" id="upload_lx" style="margin-left:20px;">
                                        <i class="layui-icon layui-icon-upload-drag"></i>上传
                                    </button>
                                    <table class="layui-table layuiadmin-page-table" id="table_lx" lay-skin="line"></table>
                                </div>
                                <div class="layui-tab-item">
                                    <div class="layui-tab-item layui-show">
                                        <button type="button" class="layui-btn layui-btn-xs" id="upload_zb" style="margin-left:20px;">
                                            <i class="layui-icon layui-icon-upload-drag"></i>上传
                                        </button>
                                        <table class="layui-table layuiadmin-page-table" id="table_zb" lay-skin="line"></table>
                                    </div>
                                </div>
                                <div class="layui-tab-item">
                                    <div class="layui-tab-item layui-show">
                                        <button type="button" class="layui-btn layui-btn-xs" id="upload_js" style="margin-left:20px;">
                                            <i class="layui-icon layui-icon-upload-drag"></i>上传
                                        </button>
                                        <table class="layui-table layuiadmin-page-table" id="table_js" lay-skin="line"></table>
                                    </div>
                                </div>
                                <div class="layui-tab-item">
                                    <div class="layui-tab-item layui-show">
                                        <button type="button" class="layui-btn layui-btn-xs" id="upload_ys" style="margin-left:20px;">
                                            <i class="layui-icon layui-icon-upload-drag"></i>上传
                                        </button>
                                        <table class="layui-table layuiadmin-page-table" id="table_ys" lay-skin="line"></table>
                                    </div>
                                </div>
                                <div class="layui-tab-item">
                                    <div class="layui-tab-item layui-show">
                                        <button type="button" class="layui-btn layui-btn-xs" id="upload_px" style="margin-left:20px;">
                                            <i class="layui-icon layui-icon-upload-drag"></i>上传
                                        </button>
                                        <table class="layui-table layuiadmin-page-table" id="table_px" lay-skin="line"></table>
                                    </div>
                                </div>
                                <div class="layui-tab-item">
                                    <div class="layui-tab-item layui-show">
                                        <button type="button" class="layui-btn layui-btn-xs" id="upload_sb" style="margin-left:20px;">
                                            <i class="layui-icon layui-icon-upload-drag"></i>上传
                                        </button>
                                        <table class="layui-table layuiadmin-page-table" id="table_sb" lay-skin="line"></table>
                                    </div>
                                </div>
                                <div class="layui-tab-item">
                                    <div class="layui-tab-item layui-show">
                                        <button type="button" class="layui-btn layui-btn-xs" id="upload_qt" style="margin-left:20px;">
                                            <i class="layui-icon layui-icon-upload-drag"></i>上传
                                        </button>
                                        <table class="layui-table layuiadmin-page-table" id="table_qt" lay-skin="line"></table>
                                    </div>
                                </div>
                            </div>
                        </div>

                        

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <div class="layui-footer">
                                    <button class="layui-btn" lay-submit="" lay-filter="save">保存</button>
                                    <button type="button" onclick="window.parent.layer.closeAll()" class="layui-btn layui-btn-primary">返回</button>
                                </div>
                            </div>
                        </div>

                    </form>
                </div>                
            </div>
        </div>
   

<script>


    var $ = layui.$
        , admin = layui.admin
        , element = layui.element
        , layer = layui.layer
        , laydate = layui.laydate
        , form = layui.form
        , table = layui.table;
        upload = layui.upload;


    form.render(null, 'saveForm');

    //设置菜单
    $('#m_project_go').addClass("layui-this");
    $('#m_project').addClass("layui-nav-itemed");


    var insStart = laydate.render({
        elem: '#StartDate'        
    });
   

    /* 自定义验证规则 */
    form.verify({
        money: [/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/, '金额格式不正确']
    });



    //加载table
    function renderTable(tableId,category) {
         var tableObj = table.render({
             elem: tableId
            , url: '/doc/getAllByObjectId?&category='+category+'&id=@Model.Item2.Id' //其他文件
            , cols: [[
                { field: 'name', title: '文件名称', width: 400, templet: '<div><a class="fileLink" href="/doc/download?id={{d.id}}">{{ d.name}}</a></div>' }, 
                {
                    field: 'opr', title: '操作', width: 120,
                    templet: '<div class="layui-table-cell laytable-cell-11-0-8"><a class="layui-btn layui-btn-danger layui-btn-xs" onclick="deleteItem(\'{{ d.id }}\')"><i class="layui-icon layui-icon-delete"></i>删除</a> </div> '
                }
                ]]
        , skin: 'line'
        });
        return tableObj;
    }

    var table_lx  = renderTable("#table_lx", 3); //立项    
    var table_zb = renderTable("#table_zb", 4);//招标
    var table_js = renderTable('#table_js', 5); //建设         
    var table_ys = renderTable("#table_ys", 6);//验收
    var table_px = renderTable("#table_px", 7);//培训
    var table_sb = renderTable("#table_sb", 8);//设备文件    
    var table_qt = renderTable("#table_qt", 9);//其他文件
 
     

       

    /* 监听提交 */
    form.on('submit(save)', function (data) {
        //开始保存合同信息
        $.post("/adminProject/save", data.field,
            function (e) {
               layer.msg(e.msg);
                if (e.code == 1) { //保存成功
                  window.parent.tableObj.reload();
                  window.parent.layer.closeAll()
              }
            });
            return false;
    });


    var id = $('#id').val();
    //上传文件
    function bindUpload(btn,category,table) {
        upload.render({
            elem: btn //绑定元素
            , url: '/doc/upload?category=' + category+'&key=' + id //上传接口,category=3项目立项文件
            , accept: 'file'
            , done: function (res) {
                layer.msg(res.msg);
                if (res.code == 1)table.reload();//上传成功，刷新附件table
            }
            , error: function () {
                layer.msg("上传失败！");
            }
        });
    }

    //绑定上传文件
    bindUpload('#upload_lx', 3, table_lx); //立项上传
    bindUpload('#upload_zb', 4, table_zb); //立项上传
    bindUpload('#upload_js', 5, table_js); //立项上传
    bindUpload('#upload_ys', 6, table_ys); //立项上传
    bindUpload('#upload_px', 7, table_px); //立项上传
    bindUpload('#upload_sb', 8, table_sb); //立项上传
    bindUpload('#upload_qt', 9, table_qt); //立项上传
    



    //删除附件
    function deleteItem(id) {
        window.parent.layer.confirm("确定要删除附件吗？", function (index){
            window.parent.layer.close(index);
            $.post("/doc/delete?id=" + id,
                function (res) {
                   layer.msg(res.msg);
                   if (res.code == 1) {
                       table_lx.reload();
                       table_zb.reload();
                       table_js.reload();
                       table_ys.reload();
                       table_px.reload();
                       table_sb.reload();
                       table_qt.reload();
                   }
           });
        });
    }

</script>
